package com.ross.service.impl;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.ross.dao.SysPermissionsMapper;
import com.ross.pojo.SysPermissions;
import com.ross.pojo.SysRoles;
import com.ross.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author RossZhang
 */
@Service
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private SysPermissionsMapper permissionMapper;
    @Autowired
    public void setPermissionsMapper(SysPermissionsMapper permissionsMapper) {
        this.permissionMapper = permissionsMapper;
    }

    @Override
    public List<SysRoles> findRoleByPermissionId(Long id) {
        return this.permissionMapper.findRoleByPermissionId(id);
    }

    @Override
    public void deleteAllPermissionsRoles(Long id) {
        this.permissionMapper.deleteAllPermissionsRoles(id);
    }

    @Override
    public void correlationRoles(Long permissionId, Long roleId) {
        this.permissionMapper.correlationRoles(permissionId, roleId);
    }

    @Override
    public SysPermissions findById(Long id) {
        return this.permissionMapper.findById(id);
    }

    @Override
    public void create(SysPermissions sysPermissions) {
        this.permissionMapper.create(sysPermissions);
    }

    @Override
    public void delete(Long id) {
        //先将和Permission相关的表数据删除
        this.permissionMapper.deleteRolePermission(id);

        //再删除Permission表数据
        permissionMapper.deletePermission(id);
    }

    @Override
    public void update(SysPermissions sysPermissions) {
        this.permissionMapper.update(sysPermissions);
    }

    @Override
    public List<SysPermissions> findAll() {
        return this.permissionMapper.findAll();
    }
}
